﻿using Uniforax.Core.GameActions;
using Uniforax.Core.WorldFramework;

namespace Uniforax.Core.Common
{
    public class ActionContext
    {
        #region properties

        public bool IsCanceled { get; private set; }

        ///<summary>游戏世界。</summary>
        public GameWorld GameWorld { get; private set; }

        public int PlayerId { get; set; }

        ///<summary>消息。</summary>
        public string Message { get; set; }

        ///<summary>历史记录。</summary>
        public List<BaseGameAction> History { get; set; } = new List<BaseGameAction>();


        #endregion

        #region ctors

        public ActionContext(GameWorld gameWorld)
        {
            GameWorld = gameWorld;
        }

        #endregion

        #region methods

        public void Undo()
        {
            for (int i = History.Count - 1; i >= 0; i--)
            {
                History[i].Undo(this);
            }
        }

        public void Cancel()
        {
            IsCanceled = true;
        }

        #endregion


    }
}
